package flc.ast.fragment;

import android.Manifest;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.CameraActivity;
import flc.ast.adapter.HomeAdapter;
import flc.ast.databinding.FragmentHomeBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.StkPermissionHelper;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HomeFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HomeFragment extends BaseNoModelFragment<FragmentHomeBinding> {

    private HomeAdapter homeAdapter;

    @Override
    protected int onCreate() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.llCamera.setOnClickListener(this);

        mDataBinding.rvHomeList.setLayoutManager(new GridLayoutManager(mContext, 2));
        homeAdapter = new HomeAdapter();
        mDataBinding.rvHomeList.setAdapter(homeAdapter);
        homeAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        getPermission(position);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.llCamera://水印相机
                CameraActivity.selPos = -1;
                startActivity(CameraActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        List<Integer> list = new ArrayList<>();
        list.add(R.drawable.y1);
        list.add(R.drawable.y2);
        list.add(R.drawable.y3);
        list.add(R.drawable.y4);
        list.add(R.drawable.y5);
        list.add(R.drawable.y6);
        list.add(R.drawable.y7);
        list.add(R.drawable.y8);
        list.add(R.drawable.y9);
        list.add(R.drawable.y10);
        list.add(R.drawable.y11);
        list.add(R.drawable.y12);
        list.add(R.drawable.y13);
        list.add(R.drawable.y14);
        homeAdapter.setList(list);
    }

    private void getPermission(int position) {
        StkPermissionHelper.permission(Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION).reqPermissionDesc(getString(R.string.get_camera_location_permission)).callback(new StkPermissionHelper.ACallback() {
            @Override
            public void onGranted() {
                CameraActivity.selPos = position + 1;
                startActivity(CameraActivity.class);
            }
        }).request();
    }

}